import { defineStore } from "pinia"
import { setToken, removeToken } from '@/util/auth'
import { getUserInfo, User } from '@api/index'
import { sleep } from '@/util/util'
export const useUserStore = defineStore("user", {
  state: () => ({
    token: '',
    userInfo: {} as User
  }),
  actions: {
    setToken(token) {
      this.token = token
      setToken(token)
    },
    async getUserInfo() {
      const res = await getUserInfo()
      this.userInfo = res.data
    },
    async logout() {
      // window.$message.loading('退出中...', { duration: 1000 })
      await sleep(1000)
      removeToken()
      this.token = ''
      this.userInfo = {}
      // window.$message.success("退出成功")
    }
  },
})
